layui.use(['table', 'layer', 'jquery'], function (data) {
    var table = layui.table,
        layer = layui.layer,
        $ = layui.jquery;


    var tableIns = table.render({
        elem: "#productionProjectList",
        height: 'full-125',
        url: ctx + '/production/selectByParamsWithProject',
        page: true,
        cellMinWidth: 80, // 单元格最小宽度
        toolbar: '#toolbarDemo',
        cols: [[// 表头
            {type: 'checkbox'},
            {type: "numbers"},
            {title: "项目单号", field: "projectNo"},
            {
                title: "产品名称", field: "productName", templet: function (data) {
                    return data.basicQuotationBean.productName;
                }
            },
            {
                title: "产品数量", field: "productCount", templet: function (data) {
                    return data.basicQuotationBean.productCount;
                }
            },
            {
                title: "规格说明", field: "description", templet: function (data) {
                    return data.basicQuotationBean.description;
                }
            },
            {
                title: "交付日期", field: "deliveryDate", templet: function (data) {
                    return data.basicQuotationBean.deliveryDate;
                }
            }, {
                title: "状态", field: "status", templet: function (data) {
                    if (data.status == 1) {
                        return "生产中"
                    }
                    if (data.status == 2) {
                        return "质检中"
                    }
                    if (data.status == 3 ){
                        return "已入库"
                    }

                }
            },

            {
                title: "操作", templet: "#tool"
            }
        ]]
    })
    table.on('tool(productionProjectFilter)', function (data) {

        if (data.event == "detail") {
            openProjectDetailDialog(data.data);
        }
        if (data.event == "quality") {
            console.log(data)
            layer.confirm("是否要提交质检", {title: "生产质检", icon: 6}, function (index) {
                layer.close(index);
                $.ajax({
                    type: "post",
                    data: {
                        projectNo: data.data.projectNo,
                    },
                    url: ctx + "/production/toQuality",
                    success: function (data) {
                        if (data.code == 200) {
                            layer.msg(data.msg);
                            tableIns.reload()
                        } else {
                            layer.msg(data.msg)
                        }
                    }, error: function (data) {
                        layer.msg(data.msg)
                    }


                })


            })
        }
    })

    function openProjectDetailDialog(data) {
        layer.open({
            type: 2,
            title: "项目---明细",
            content: ctx + "/production/detail?projectId=" + data.id,
            area: ['700px', '500px'],
            shadeClose: true,
            maxmin: true
        })
    }
})